import excel "C:\Users\SIMU13\Downloads\trust_stata.xlsx", sheet("trust_stata") firstrow case(lower) clear


*average values
sort partynegative
by partynegative : summarize value

sort partypositive
by partypositive : summarize value

sort partyrandom
by partyrandom : summarize value

sort placeboingroup
by placeboingroup : summarize value

sort placebooutgroup
by placebooutgroup : summarize value

sort imigr_neg_neg
by imigr_neg_neg : summarize value

sort imigr_neg_pos
by imigr_neg_pos : summarize value

sort imigr_pos_neg
by imigr_pos_neg : summarize value

sort imigr_pos_pos
by imigr_pos_pos : summarize value

sort imigr_neut_neut
by imigr_neut_neut : summarize value


* multilevel negative binomial regression
. metobit value imigr_neg_neg  imigr_neg_neut imigr_neg_pos imigr_neut_neg imigr_neut_pos imigr_neut_neut imigr_pos_neg  imigr_pos_neut  imigr_pos_pos partynegative partypositive nonvoter partyrandom placeboingroup placebooutgroup || responseid:,  ll(0) ul(100)
margins, dydx(*) post
marginsplot, horizontal xline(0) yscale(reverse) recast(scatter)

. metobit value imigr_neg_neg  imigr_neg_neut imigr_neg_pos imigr_neut_neg imigr_neut_pos imigr_neut_neut imigr_pos_neg  imigr_pos_neut  imigr_pos_pos partynegative partypositive nonvoter c.sympathy##i.partyrandom placeboingroup placebooutgroup || responseid:,  ll(0) ul(100)
margins partyrandom, at(sympathy=(0(1)10)) vsquish
marginsplot
. estimates store F

. coefplot F, drop(_cons) xline(0)

*multilevel negative binomial regression
. mepoisson value imigr_neg_neg  imigr_neg_neut imigr_neg_pos imigr_neut_neg imigr_neut_pos imigr_neut_neut imigr_pos_neg  imigr_pos_neut  imigr_pos_pos partynegative partypositive nonvoter partyrandom placeboingroup placebooutgroup  || responseid:, irr
. mepoisson value imigr_neg_neg  imigr_neg_neut imigr_neg_pos imigr_neut_neg imigr_neut_pos imigr_neut_neut imigr_pos_neg  imigr_pos_neut  imigr_pos_pos partynegative partypositive nonvoter c.sympathy##i.partyrandom placeboingroup placebooutgroup  || responseid:, irr

*conjoint as multilevel tobi
import excel "C:\Users\SIMU13\Downloads\conjoint_stata.xlsx", sheet("conjoint_stata") firstrow clear
encode partisanmatch , gen( ipartisanmatch )
encode immigrationmatch , gen( iimmigrationmatch )
encode politicaltalkmatch , gen( ipoliticaltalkmatch )
encode valuesmatch , gen( ivaluesmatch )
encode gendermatch , gen( igendermatch )
encode educationmatch , gen( ieducationmatch )

fvset base 2 ipartisanmatch
fvset base 2 iimmigrationmatch
fvset base 4 ipoliticaltalkmatch
fvset base 3 ivaluesmatch
fvset base 2 igendermatch
fvset base 2 ieducationmatch
. metobit rating  i.ipartisanmatch  i.iimmigrationmatch i.ipoliticaltalkmatch i.ivaluesmatch i.igendermatch i.ieducationmatch || id_ok:,  ll(0) ul(100)

import excel "C:\Users\SIMU13\Downloads\trust_stata.xlsx", sheet("trust_stata") firstrow case(lower) clear
keep if partypref==1
. metobit value imigr_neg_neg  imigr_neg_neut imigr_neg_pos imigr_neut_neg imigr_neut_pos imigr_neut_neut imigr_pos_neg  imigr_pos_neut  imigr_pos_pos partynegative partypositive nonvoter partyrandom placeboingroup placebooutgroup || responseid:,  ll(0) ul(100)
margins, dydx(*) post
marginsplot, horizontal xline(0) yscale(reverse) recast(scatter)



